package com.qzf.test.model;

import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class Brand  extends Component {

    private  String name;
    private Image image;
    private  Image grayImage;
    private boolean isGray;

    private Integer width;
    private Integer height;
    private Integer x;
    private Integer y;

    private Cell cell;

    public Cell getCell() {
        return cell;
    }

    public void setCell(Cell cell) {
        this.cell = cell;
    }

    public Brand(String name){
        this.name=name;
        this.image=Toolkit.getDefaultToolkit().getImage("imgs/"+name+".png");
        this.grayImage=Toolkit.getDefaultToolkit().getImage("imgs/"+name+"_gray.png");
        this.isGray=false;
        this.width=50;
        this.height=50;
        this.x=0;
        this.y=0;
        this.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                Brand b=(Brand) e.getSource();
                if(b.isGray ||b.getName().equals("背景草地")||b.getName().equals("消除区域")){
                    return;
                }else{
                    //b.getParent().remove(b);
                    EleBox.add(b);
                    cell.setState(0);
                    cell.setBrand(null);

                    // 当卡牌被点击后，通知EleBox类，由它负责消除逻辑
                    // 不需要直接引用star类
                }
            }
        });
    }

    @Override
    public void paint(Graphics g) {
        if (this.isGray == true) {
            g.drawImage(this.grayImage, this.x, this.y, null);
        }else{
            g.drawImage(this.image,this.x,this.y,null);
        }
        // repaint();
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Image getImage() {
        return image;
    }

    public void setImage(Image image) {
        this.image = image;
    }

    public Image getGrayImage() {
        return grayImage;
    }

    public void setGrayImage(Image grayImage) {
        this.grayImage = grayImage;
    }

    public boolean isGray() {
        return isGray;
    }

    public void setGray(boolean gray) {
        isGray = gray;
    }



}
